//
//  YTStashRecordsListTableViewCell.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/11/18.
//

#import "YTStashRecordsListTableViewCell.h"

@interface YTStashRecordsListTableViewCell ()
@property (nonatomic ,strong) UIView * makeview;
@property (nonatomic ,strong) UILabel * createTime;
@property (nonatomic ,strong) UILabel * type;
@property (nonatomic ,strong) UIImageView * productImg;
@property (nonatomic ,strong) UILabel * name;
@property (nonatomic ,strong) UILabel * productBrand;

@property (nonatomic ,strong) UILabel * product;
@property (nonatomic ,strong) UILabel * LimitMSLab;
@property (nonatomic ,strong) UILabel * LimitLab;
@property (nonatomic ,strong) UILabel * stockNumber;
@property (nonatomic ,strong) UILabel * stockNumberMSLab;


@end

@implementation YTStashRecordsListTableViewCell



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setupView];
    }
    return self;
}


- (void)setupView{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    self.userInteractionEnabled = YES;
    self.contentView.userInteractionEnabled = YES;

    UIView * makeview = [UIView new];
    self.makeview = makeview;
    makeview.backgroundColor = UIColor.whiteColor;
    [self.contentView addSubview:makeview];
    [makeview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.offset(0);
        make.bottom.offset(kwt(-10));
    }];
    
    UILabel * createTime = [DTKTool labelWithText:@"--" andFont:kFont(14) andTextColor:KcolorHex(@"#787A79")];
    self.createTime = createTime;
    [makeview addSubview:createTime];
    [createTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(15));
        make.left.offset(kwt(12));
    }];
    
    UILabel * type = [DTKTool labelWithText:@"--" andFont:kCFont(13) andTextColor:UIColor.whiteColor];
    self.type = type;
    type.textAlignment = NSTextAlignmentCenter;
    type.backgroundColor = KcolorHex(@"#FF9215");
    [DTKTool YJ:kwt(3) andView:type];
    [makeview addSubview:type];
    [type mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(12));
        make.right.offset(kwt(-12));
        make.width.offset(kwt(40));
        make.height.offset(kwt(21));
    }];
    
    UIImageView * productImg = kimageView(@"tangkou_photo");
    self.productImg = productImg;
    [DTKTool YJ:kwt(4) andView:productImg];
    [makeview addSubview:productImg];
    [productImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(21));
        make.width.height.offset(kwt(66));
        make.top.offset(kwt(43));
    }];
    
    UILabel * name = [DTKTool labelWithText:@"--" andFont:kCFont(17) andTextColor:KcolorHex(@"#222222")];
    self.name = name;
    [makeview addSubview:name];
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(45));
        make.left.offset(kwt(92));
        make.right.offset(kwt(-12));
    }];
    
    UILabel * pplab = [DTKTool labelWithText:@"品牌" andFont:kFont(13) andTextColor:KcolorHex(@"#FEF8E3")];
    pplab.textAlignment = NSTextAlignmentCenter;
    [DTKTool BFYJ:kwt(3) andView:pplab andCorner:UIRectCornerTopLeft|UIRectCornerBottomLeft andSize:CGRectMake(0,0,kwt(32), kwt(21))];
    pplab.backgroundColor = [UIColor gradientColorWithSize:CGSizeMake(kwt(32), 1) direction:GradientColorDirectionLevel startColor:KcolorHex(@"#4F5680") endColor:KcolorHex(@"#252638")];
    [makeview addSubview:pplab];
    [pplab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(73));
        make.left.offset(kwt(92));
        make.width.offset(kwt(32));
        make.height.offset(kwt(21));
    }];
    UILabel * productBrand = [DTKTool labelWithText:@"--" andFont:kFont(13) andTextColor:KcolorHex(@"#6E3E00")];
    self.productBrand = productBrand;
    productBrand.textAlignment = NSTextAlignmentCenter;
    [DTKTool BFYJ:kwt(3) andView:productBrand andCorner:UIRectCornerTopRight|UIRectCornerBottomRight andSize:CGRectMake(0,0,kwt(32), kwt(21))];
    productBrand.backgroundColor = [UIColor gradientColorWithSize:CGSizeMake(kwt(32), 1) direction:GradientColorDirectionLevel startColor:KcolorHex(@"#FFE5CC") endColor:KcolorHex(@"#FFEBC2")];
    [makeview addSubview:productBrand];
    [productBrand mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(pplab.mas_right);
        make.centerY.equalTo(pplab);
        make.width.offset(kwt(32));
        make.height.offset(kwt(21));
    }];
    
    UILabel * templab = [DTKTool labelWithText:@"规格/单位：" andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
    [makeview addSubview:templab];
    [templab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(106));
        make.left.offset(kwt(92));
    }];
    
    
    UILabel * product = [DTKTool labelWithText:@"--" andFont:kFont(15) andTextColor:KcolorHex(@"#222222")];
    self.product = product;
    [makeview addSubview:product];
    [product mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(templab);
        make.left.equalTo(templab.mas_right).offset(kwt(4));
    }];
    
    UIView * backview = [UIView new];
    backview.backgroundColor = KcolorHex(@"#FAFCFF");
    [DTKTool YJBK:kwt(4) andView:backview andWidth:0.5 andColor:KcolorHex(@"#E3E9F1")];
    [makeview addSubview:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(133));
        make.left.offset(kwt(92));
        make.right.offset(kwt(-21));
        make.height.offset(kwt(54));
    }];
    
    UIView * line = [UIView new];
    line.backgroundColor = KcolorHex(@"#D5D5D5");
    [backview addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.offset(0);
        make.width.offset(0.5);
        make.height.offset(kwt(29));
    }];
    
    UILabel * LimitMSLab = [DTKTool labelWithText:@"库存下限" andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
    self.LimitMSLab = LimitMSLab;
    [backview addSubview:LimitMSLab];
    [LimitMSLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(8));
        make.left.offset(kwt(16));
    }];
    UILabel * LimitLab = [DTKTool labelWithText:@"--" andFont:kFont(15) andTextColor:KcolorHex(@"#222222")];
    self.LimitLab = LimitLab;
    [backview addSubview:LimitLab];
    [LimitLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(31));
        make.height.offset(kwt(15));
        make.centerX.equalTo(LimitMSLab);
    }];
    
    UILabel * templab1 = [DTKTool labelWithText:@"预警库存数" andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
    [backview addSubview:templab1];
    self.stockNumberMSLab = templab1;
    [templab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(8));
        make.right.offset(kwt(-16));
    }];
    
    UILabel * stockNumber = [DTKTool labelWithText:@"" andFont:kFont(15) andTextColor:KcolorHex(@"#222222")];
    self.stockNumber = stockNumber;
    stockNumber.textAlignment = NSTextAlignmentRight;
    [backview addSubview:stockNumber];
    [stockNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(31));
        make.height.offset(kwt(15));
        make.right.offset(kwt(-16));
        make.left.offset(kwt(16));
    }];
}

- (void)setModel:(YTStashRecordModel *)model{
    _model = model;
    
    if(model.type == 1){//出入库类型 0:入库 1:出库
        self.createTime.text = [NSString stringWithFormat:@"出库时间:%@",model.createTime ];

        self.type.text = @"出库";
        self.type.backgroundColor = KcolorHex(@"#FF5C0A");
        self.LimitMSLab.text = @"出库数量";
        self.LimitLab.text = [NSString stringWithFormat:@"%lu%@",model.number,model.normsName];
        self.stockNumberMSLab.text = @"领用人";
        self.stockNumber.text = model.createBy;
    } else if(model.type == 0){//入库
        self.createTime.text = [NSString stringWithFormat:@"入库时间:%@",model.createTime ];
        self.type.text = @"入库";
        self.type.backgroundColor = KcolorHex(@"#2672FC");
        self.LimitMSLab.text = @"入库数量";
        self.LimitLab.text = [NSString stringWithFormat:@"%lu%@",model.number,model.normsName];
        self.stockNumberMSLab.text = @"交货人";
        self.stockNumber.text = model.deliveryName;
    }
    [self.productImg LZsetImageWithImagePath:model.productImg placeholderImage:[UIImage imageNamed:@"tangkou_photo"]];
    self.name.text = model.name;
    self.productBrand.text = model.productBrand;
    CGFloat productBrandW = [DTKTool textWithtitle:model.productBrand andSize:CGSizeMake(1000, 10) andFout:kFont(13)].width + kwt(8);
    if(productBrandW > kwt(220)){
        productBrandW = kwt(220);
    }
    [self.productBrand mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.offset(productBrandW);
    }];
    self.productBrand.backgroundColor = [UIColor gradientColorWithSize:CGSizeMake(productBrandW, 1) direction:GradientColorDirectionLevel startColor:KcolorHex(@"#FFE5CC") endColor:KcolorHex(@"#FFEBC2")];
    [DTKTool BFYJ:kwt(3) andView:self.productBrand andCorner:UIRectCornerTopRight|UIRectCornerBottomRight andSize:CGRectMake(0,0,productBrandW, kwt(21))];

    self.product.text = [NSString stringWithFormat:@"%@/%@",model.productNorms,model.normsName];
//    self.stockNumber.text = model;
}
@end
